import java.io.FileWriter;
import java.text.SimpleDateFormat;
import java.util.Date;



/**
 * Created by blatand on 2017/2/10.
 */
public class DataSaveUtil {


    static final int  FILE              = 1;
    static final int  DATABASE          = 2;
    static final int  CONSOLE           = 3;

    static void SaveParseMsg(Msg8583Util input8583bag,String filePath,String refilePath,int type){
        Date now = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        String curTime = dateFormat.format( now );

        FileWriter fop = null;
        FileWriter reWritefop = null;
        try{
            fop = new FileWriter(filePath, true);
            reWritefop = new FileWriter(refilePath);
            fop.write("======================"+curTime+"=======================\n");      //save current time
            for(int i=1;i<128+1;i++){
                if(input8583bag.getBit(i)>0){

                    switch(type){

                        case FILE:
                            fop.write(ToolUtil.getHexString(i,input8583bag.getSpecifiedMsgValue(i),input8583bag.getSpecifiedMsgLen(i)));
                            reWritefop.write(ToolUtil.getHexString(i,input8583bag.getSpecifiedMsgValue(i),input8583bag.getSpecifiedMsgLen(i)));
                            break;

                        case DATABASE:
                            break;

                        case CONSOLE:
                            break;

                        default:
                            break;
                    }
                }
            }
            reWritefop.write("\n");
            fop.write("\n");
            reWritefop.close();
            fop.close();
        }catch (Exception e){

        }

    }

    static void SaveOriginalMsg(String inputMsg,String filePath,int type){

        Date now = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        String curTime = dateFormat.format( now );

        FileWriter fop = null;
        try{
            fop = new FileWriter(filePath, true);

            fop.write("======================"+curTime+"=======================\n");      //save current time

                switch(type){

                    case FILE:
                        fop.write(inputMsg);
                        break;

                    case DATABASE:
                        break;

                    case CONSOLE:
                        break;

                    default:
                        break;
                }
            fop.write("\n");
            fop.close();
        }catch (Exception e){

        }

    }
}
